﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace PopShops.Entities
{
    public class Deal
    {
        #region Public Properties
        
        [XmlAttribute("name")]
        public string Name { get; set; }
        [XmlAttribute("description")]
        public string Description { get; set; }
        [XmlAttribute("url")]
        public string Url { get; set; }
        [XmlAttribute("image_url")]
        public string ImageUrl { get; set; }
        [XmlAttribute("specific")]
        public bool Specific { get; set; }
        [XmlAttribute("code")]
        public string Code { get; set; }
        //Comma separated IDs
        [XmlAttribute("deal_type_ids")]
        public string DealTypeIDs { get; set; }
        [XmlAttribute("restrictions")]
        public string Restrictions { get; set; }
        [XmlAttribute("merchant_id")]
        public int MerchantID { get; set; }
        [XmlAttribute("merchant_type_id")]
        public int MerchantTypeID { get; set; }
        [XmlAttribute("network_merchant_id")]
        public string NetworkMerchantID { get; set; }

        [XmlAttribute("network_id")]
        public string network_id;
        public int NetworkID
        {
            get
            {
                if (string.IsNullOrEmpty(network_id))
                    return 0;

                return int.Parse(network_id);
            }
        }

        [XmlAttribute("start_on")]
        public string start_on;
        [XmlAttribute("end_on")]
        public string end_on;

        public DateTime StartOn 
        {
            get
            {
                return DateTime.Parse(start_on);
            }
        }
        public DateTime EndOn 
        {
            get
            {
                return DateTime.Parse(end_on);
            }
        }
        #endregion

        #region Ctor

        public Deal()
        { }

        public Deal(string name, string description, string url, string image_url, bool specific, string start_on, string end_on, 
            string code, string deal_type_ids, string restrictions, int merchant_id, int merchant_type_id)
        {
            this.Code = code;
            this.DealTypeIDs = deal_type_ids;
            this.Description = description;
            this.end_on = end_on;
            this.ImageUrl = image_url;
            this.MerchantID = merchant_id;
            this.MerchantTypeID = merchant_type_id;
            this.Name = name;
            this.Restrictions = restrictions;
            this.Specific = specific;
            this.start_on = start_on;
            this.Url = url;
        }

        #endregion
    }

    [XmlRoot("deals")]
    public class Deals
    {
        public Deals()
        { }

        [XmlAttribute("total_count")]
        public long TotalCount { get; set; }

        [XmlElement("deal")]
        public List<Deal> DealCollection { get; set; }
    }

    public enum DealSort
    {
        none,
        start_on_asc,
        start_on_desc,
        end_on_asc,
        end_on_desc,
        merchant_name_asc,
        merchant_name_desc
    }
}
